﻿using ARS.Common.Helper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Npgsql;
using System.Data.SqlClient;

namespace ARS.Common.Service.ExecScripts
{
    /// <summary>
    ///执行SQL语句的类
    /// </summary>
    public class PgExecScript : IExecScript
    {
        public Tuple<DataSet, bool, string> ExecSql(string coonStr, string script)
        {
            using (NpgsqlConnection con = new NpgsqlConnection(coonStr))
            {
                DataSet ds = new DataSet();
                var isOK = false;
                var message = "";
                try
                {
                    using (NpgsqlDataAdapter da = new NpgsqlDataAdapter(script, con))
                    {
                        da.Fill(ds);
                        da.Dispose();
                        isOK = true;
                    };
                }
                catch (Exception ex)
                {
                    message = $"出错信息:\r\n Message{ex.Message} \r\n StackTrace:{ex.StackTrace}";
                  //  Log.WriteLine(message);
                }
                finally
                {
                    con.Close();//关闭数据库
                }
               
                return Tuple.Create( ds,isOK, message);
            }
        }
    }
}
